package mww.javabean.service;

import java.util.List;
import java.util.Map;
import java.util.Vector;

import mww.common.DaoException;
import mww.javabean.dao.StudentDaoImpl;
import mww.javabean.dao.StudentDao;

import mww.common.ServiceException;
import mww.javabean.entity.Student;

public class StudentServiceImpl implements StudentService {
	private StudentDao studentDao = new StudentDaoImpl();

	// 添加一个学生
	public void addStudent(Student student) throws ServiceException {
		try {
			studentDao.addStudent(student);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

	@Override
	public void delStudent(String studentNo) throws ServiceException {
		try {
			studentDao.delStudent(studentNo);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

	@Override
	public void updateStudent(Student student) throws ServiceException {
		try {
			studentDao.updateStudent(student);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

	// 列表显示所有学生列表--分页
	public Map findAllStudent(int curPage) throws ServiceException {
		Map map = null;
		try {
			map = studentDao.findAllStudent(curPage);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return map;
	}

	// 根据学号查找学生
	@Override
	public Student findStudentByStudentNo(String studentNo) throws ServiceException {
		Student student = null;
		try {
			student = studentDao.findStudentByStudentNo(studentNo);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return student;
	}

	@Override
	public List findAllStudentByClass(String cls) throws ServiceException {
		List list = null;
		try {
			list = studentDao.findAllStudentByClass(cls);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return list;
	}

	@Override
	public List findAllStudentByMajor(String major) throws ServiceException {
		List list = null;
		try {
			list = studentDao.findAllStudentByMajor(major);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return list;
	}

	@Override
	public int getStudentTotality() {
		Integer number = null;
		try {
			number = studentDao.findAllStudent().size();
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return number;
	}

	// 更改密码
	@Override
	public void updateStudentPwd(String StudentNo, String pwd) {
		try {
			studentDao.updateStudentPwd(StudentNo, pwd);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}

	}

	@Override
	public List findAllStudent() throws ServiceException {
		List list = null;
		try {
			list = studentDao.findAllStudent();
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return list;
	}

	@Override
	public List findAllStudentByMostCon(Student condition) throws ServiceException {
		List list = null;
		try {
			list = studentDao.findAllStudentByMostCon(condition);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return list;
	}

	@Override
	public Map findAllStudentByMostCon(Student condition, Integer curPage) throws ServiceException {
		Map map = null;
		try {
			map = studentDao.findAllStudentByMostCon(condition, curPage);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return map;
	}

	@Override
	public Map findAllStudent(Integer curPage) throws ServiceException {
		Map map = null;
		try {
			map = studentDao.findAllStudent(curPage);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return map;
	}

	@Override
	public void updateScore(String studentNo, float sumCredit, float sumCreditGPA, float avgCreditGPA) {
		try {
			studentDao.updateScore(studentNo, sumCredit, sumCreditGPA, avgCreditGPA);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

	@Override
	public Vector findAllMajor() throws ServiceException {
		Vector all = null;
		try {
			all = studentDao.findAllMajor();
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return all;
	}

	@Override
	public Vector findAllClass() throws ServiceException {
		Vector all = null;
		try {
			all = studentDao.findAllClass();
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return all;
	}

	@Override
	public void updateClassRank(String studentNo, int classRank) throws ServiceException {
		try {
			studentDao.updateClassRank(studentNo, classRank);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

	@Override
	public void updateMajorRank(String studentNo, int majorRank) throws ServiceException {
		try {
			studentDao.updateMajorRank(studentNo, majorRank);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

}
